<script setup>

import { onMounted, ref,defineProps, onBeforeMount } from 'vue';
import { useRouter } from 'vue-router';
const $router = useRouter()
const props = defineProps({
    swiperData:{
        type: Array,
        default:()=>[]
    }
})

let index = ref(0)

const onChange = () => {
    setInterval(() => {
        index.value++
        if (index.value >= props.swiperData.length) {
            index.value = 0
        }
    }, 2500)
}
onMounted(() => {
    onChange()
})
</script>

<template>
    <div class="swiper">
        <div class="swiper-box">
            <div class="swiper-bkg">
                <img :src="swiperData[index].articleImg" alt="">
            </div>
            <div class="title-box">
                <div class="category">
                    <svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-sanjiaoright"></use>
                    </svg>
                    <span>推荐文章</span>
                </div>
                <h1>{{ swiperData[index].title}}</h1>
                <div class="btn-box">
                    <div class="btn" @click="$router.push(`/articleDetail/${swiperData[index].articleId}`)">READ MORE</div>
                    <div class="btn-t">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-localoffer"></use>
                        </svg>
                        <span>Next</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
// 这个是轮播图的伸缩动画
@keyframes swiperLoop {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: .1;
    }

}
// 这个是按钮的位移动画
@keyframes btnAnimation {
    0% {
        transform: translate(-200px, 0);
    }

    100% {
        transform: translate(0, 0);
    }
}
// next的位移动画
@keyframes btntAnimation {
    0% {
        transform: translate(0, 200px);
    }

    100% {
        transform: translate(0, 0);
    }
}
// 渐变动画，暂时没有生效
@keyframes loopGradient {
    0% {
        background-image: linear-gradient(90deg, rgb(8, 217, 214), rgb(234, 234, 234), rgb(8, 217, 214));
    }
    100% {
        background-image: linear-gradient(90deg, rgb(234, 234, 234), rgb(8, 217, 214), rgb(234, 234, 234));
    }

}
// 轮播图载入动画
@keyframes swiperLoad {
    0% {
        transform: translate(-50%, -50%);
    }

    100% {
        transform: translate(0, 0);
        
    }
}

// 轮播图样式开始
.swiper {
    min-width: 520px;
    min-height: 200px;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 5px;
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    animation: swiperLoad .5s ease-in-out;
}


.swiper-box {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #fff;
    border-radius: 10px;
    overflow: hidden;

    .swiper-bkg {
        z-index: 1;
        width: 100%;
        height: 100%;
        border-radius: 10px;
        overflow: hidden;
        // 图片
        img {
            width: 100%;
            height: 100%;
            animation: swiperLoop 5s linear infinite;
        }
    }

    .title-box {
        // background-color: red;
        position: absolute;
        height: 250px;
        width: 500px;
        left: 50px;
        bottom: 100px;
        z-index: 2;
        padding: 20px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .category {
            display: flex;
            justify-content: left;
            align-items: center;
            // margin-top: 20px;
            color: #fff;

            .icon {
                width: 16px;
                height: 16px;
                margin-right: 5px;
                fill: red;
            }

            span {
                font-size: 16px;
                // font-weight: 700;
                line-height: 16px;
            }
        }

        h1 {
            color: #fff;
            font-weight: 500;
            line-height: 36px;
        }

        // 按钮样式
        .btn-box {
            .btn {
                width: 90px;
                height: 30px;
                background-image: linear-gradient(90deg, rgb(8, 217, 214), rgb(234, 234, 234), rgb(8, 217, 214));
                border: 1px solid #88E3E2;
                color: #fff;
                font-size: 12px;
                font-weight: 700;
                line-height: 30px;
                border-radius: 15px;
                text-align: center;
                justify-content: center;
                margin-bottom: 20px;
                transform: translate(-200px, 0);

                &:hover {
                    // hover发光
                    box-shadow: 0 0 10px 10px #e6fcfb;
                    cursor: pointer;

                    animation: loopGradient 1s linear infinite;


                }
            }

            .btn-t {
                transform: translate(0, 200px);
                display: flex;
                justify-content: left;
                align-items: center;
                margin-top: 10px;
                color: #fff;
                cursor: pointer;

                .icon {
                    width: 20px;
                    height: 20px;
                    margin: 0 5px;
                    fill: gray;
                }

                span {
                    border-left: 1px solid gray;
                    padding-left: 10px;
                    font-size: 12px;
                    font-weight: 700;
                    line-height: 20px;
                }
            }

        }
    }

    .title-box:hover {
        overflow: hidden;

        .btn-box {

            .btn {
                animation: btnAnimation .5s linear forwards;
            }

            .btn-t {
                animation: btntAnimation .5s linear forwards;
            }
        }
    }
}
</style>